package com.soft.javase.day13;

import java.util.concurrent.LinkedBlockingQueue;

/**
 * @author yzh
 * @desc TODO
 * @date 2025/5/22
 */
public class LinkedBlockingQueueDemo {
    public static void main(String[] args) {
        LinkedBlockingQueue<String> queue = new LinkedBlockingQueue<>();

        new Thread(() -> {
            try {
                System.out.println("C");
                queue.put("B");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        },"线程C").start();

        new Thread(() -> {
            try {
                if (queue.take().equals("B")) {
                    System.out.println("B");
                    queue.put("A");
                }
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        },"线程B").start();

        new Thread(() -> {
            try {
                if (queue.take().equals("A")) {
                    System.out.println("A");
                }
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        },"线程A").start();
    }
}
